package com.gai.shop.web.controller;

import com.alibaba.fastjson.JSON;
import com.gai.shop.entity.Type;
import com.gai.shop.service.TypeService;
import com.gai.shop.service.impl.TypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class TypeController extends BaseController {
//    public void getTypeAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        TypeService ts = new TypeServiceImpl();
//        List<Type> typeList = ts.selectTypeAll();
//        for (Type type : typeList) {
//            System.out.println("hh"+type);
//        }
//    }
//
//    public void setType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String name = request.getParameter("name");
//        response.getWriter().println("name="+name);
//    }

    private final TypeService TS = new TypeServiceImpl();

    public String getAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取数据
        List<Type> typeList = TS.selectTypeAll();
        //把集合转换为JSON
        String s = JSON.toJSONString(typeList);
        //写出响应
        return s;
    }
}
